package com.example.mall.web.controller;

import com.example.mall.domain.CouponReceive;
import com.example.mall.dto.CouponReceiveDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.CouponReceiveQuery;
import com.example.mall.query.PageDTO;
import com.example.mall.result.JSONResult;
import com.example.mall.service.ICouponReceiveService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/couponReceive")
public class CouponReceiveController {

    @Autowired
    public ICouponReceiveService couponReceiveService;

    /**
     * 分页查询优惠券领取记录表信息
     * @param couponReceiveQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询优惠券领取记录表信息",notes = "分页查询优惠券领取记录表信息",httpMethod = "GET")
    public JSONResult queryPage(CouponReceiveQuery couponReceiveQuery){
        PageDTO<CouponReceiveDto> couponReceiveDtoPageDTO = couponReceiveService.queryPage(couponReceiveQuery);
        return JSONResult.success("查询成功",couponReceiveDtoPageDTO);
    }

    /**
     * 根据id查询优惠券领取记录表信息
     * @param receiveId
     * @return
     */
    @GetMapping("query/{receiveId}")
    @ApiOperation(value = "根据id查询优惠券领取记录表信息",notes = "根据id查询优惠券领取记录表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("receiveId")Long receiveId){
        //1.根据id查询用户信息
        if (receiveId == null){
            throw new GlobalCustomerException(ErrorEnumCode.RECEIVEID_NOT_ID);
        }
        CouponReceive couponReceive = couponReceiveService.getById(receiveId);
        return JSONResult.success("查询成功",couponReceive);
    }

    /**
     * 根据id查询优惠券领取记录表信息
     * @param receiveId
     * @return
     */
    @GetMapping("queryCouponReceiveById/{receiveId}")
    @ApiOperation(value = "根据id查询优惠券领取记录表信息",notes = "根据id查询优惠券领取记录表信息",httpMethod = "GET")
    public JSONResult queryCouponReceiveById(@PathVariable("receiveId")Long receiveId){
        //1.根据id查询用户信息
        if (receiveId == null){
            throw new GlobalCustomerException(ErrorEnumCode.RECEIVEID_NOT_ID);
        }
        CouponReceive couponReceive = couponReceiveService.queryCouponReceiveById(receiveId);
        return JSONResult.success("查询成功",couponReceive);
    }

    /**
     * 查询全部优惠券领取记录表信息
     * @param
     * @return
     */
    @GetMapping("queryCouponReceiveList")
    @ApiOperation(value = "查询全部优惠券领取记录表信息",notes = "查询全部优惠券领取记录表信息",httpMethod = "GET")
    public JSONResult queryCouponReceiveList(){
        List<CouponReceive> couponReceives = couponReceiveService.queryCouponReceiveList();
        return JSONResult.success("查询成功",couponReceives);
    }

    /**
     * 新增优惠券领取记录表
     * @param couponReceiveDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增优惠券领取记录表",notes = "新增优惠券领取记录表",httpMethod = "POST")
    public JSONResult insert(@RequestBody CouponReceiveDto couponReceiveDto){
        couponReceiveService.insert(couponReceiveDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改优惠券领取记录表信息
     * @param couponReceiveDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改优惠券领取记录表信息",notes = "修改优惠券领取记录表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody CouponReceiveDto couponReceiveDto){
        couponReceiveService.update(couponReceiveDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除优惠券领取记录表信息
     * @param receiveId
     * @return
     */
    @PostMapping("delete/{receiveId}")
    @ApiOperation(value = "删除优惠券领取记录表信息",notes = "删除优惠券领取记录表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("receiveId") Long receiveId) {
        couponReceiveService.delete(receiveId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除优惠券领取记录表信息
     * @param receiveIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除优惠券领取记录表信息",notes = "批量删除优惠券领取记录表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> receiveIds) {
        couponReceiveService.deleteBatch(receiveIds);
        return JSONResult.success("批量删除成功");
    }
}
